<template>
  <div>
    <div class="date-select">
      <el-text tag="b" size="large">热门分类</el-text>
    </div>
    <div id="pieChart" style="width: 100%; height: 300px"></div>
  </div>
</template>

<script setup lang="ts">
import { ref, watch } from "vue";
import type { EChartsOption } from "@/config/echarts";
import {echarts} from "@/config/echarts";
import type { popularCategoriesRes } from "@/types/index";
interface Props {
  data: popularCategoriesRes[];
}
const propsData = defineProps<Props>();
watch(propsData, (newval) => {
  var myChart = echarts.init(document.getElementById("pieChart"));
  var option: EChartsOption;
  window.addEventListener("resize", function () {
    myChart.resize(); //跟随浏览器改变尺寸
  });
  option = {
    tooltip: {
      trigger: "item",
    },
    legend: {
      top: "2%",
      left: "center",
    },
    series: [
      {
        type: "pie",
        radius: "50%",
        data: newval.data,
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: "rgba(0, 0, 0, 0.5)",
          },
        },
        top: 30,
      },
    ],
  };

  option && myChart.setOption(option);
});
</script>

<style scoped>
.date-select {
  display: flex;
  align-items: center;
  height: 32px;
}
</style>
